// pages/loupan/comment/write.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    content: '',
    id: '',
    opid:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var id = options.id;
    // var opid = wx.getStorageSync('user').openid;
    this.setData({
      id: id,
      // opid: opid,
    })
  },
  textareaBInput(e) {
    var that = this
    var val = e.detail.value;
    that.setData({
      content: val
    });
  }, // 获取textarea 值

  submit() {
    var that = this;
    var content = that.data.content;
    var opid = wx.getStorageSync('user_new');
    // var opid ='oe_-o5daoHoRkihnEmUouT2moarU';
    var loupanid = that.data.id;
    if (content == '') {
      wx.showToast({
        title: '请输入问答内容',
        duration: 1000,
        icon: 'none',
      })
    } else {
      wx.showLoading({
        title: '提交中',
      })
      app.core('post', 'create_loupan_wenda', {
        loupan_id: loupanid,
        p_xiaochengxu_user_id: 0,
        content: content,
        p_wenda_id: 0,
        open_id: opid
      }, (res => {
        console.log(res)
        
        if (res.resultCode == 200) {
          wx.showToast({
            title: '评论成功',
            icon: 'none',
            duration: 1000
          })
          wx.hideLoading();

          setTimeout(function() {
            wx.reLaunch({
              url: '/pages/loupan/detail?id=' + loupanid + '',
            })
          }, 1000)
        }
      }))

    }
  }, // 表单提交
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})